/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            housekeepingFeeConfigManageInfo: {
                housekeepingFeeConfigs: [],
                total: 0,
                records: 1,
                moreCondition: false,
                configId: '',
                feeTypes: [],
                isDefaults: [],
                conditions: {
                    feeName: '',
                    isDefault: '',
                    feeTypeCd: '',
                    startTime: '',
                    endTime: '',
                    shopId: vc.getCurrentCommunity().shopId
                }
            }
        },
        _initMethod: function () {
            //URL取值使用getParam方法
            $that.housekeepingFeeConfigManageInfo.configId = vc.getParam('configId');
            $that.housekeepingFeeConfigManageInfo.conditions.configId = $that.housekeepingFeeConfigManageInfo.configId;
            $that._listHousekeepingFeeConfigs(DEFAULT_PAGE, DEFAULT_ROWS);
            vc.getDict('housekeeping_fee_config', "is_default", function (_data) {
                $that.housekeepingFeeConfigManageInfo.isDefaults = _data;
            });
        },
        _initEvent: function () {
            vc.on('housekeepingFeeConfigManage', 'listHousekeepingFeeConfig', function (_param) {
                $that._listHousekeepingFeeConfigs(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listHousekeepingFeeConfigs(_currentPage, DEFAULT_ROWS);
            });
            $that._listHousekeepingFeeTypes(1, 50);
        },
        methods: {
            _listHousekeepingFeeConfigs: function (_page, _rows) {
                $that.housekeepingFeeConfigManageInfo.conditions.page = _page;
                $that.housekeepingFeeConfigManageInfo.conditions.row = _rows;
                var param = {
                    params: $that.housekeepingFeeConfigManageInfo.conditions
                };
                param.params.feeName = param.params.feeName.trim();
                //发送get请求
                vc.http.apiGet('/housekeepingFeeConfig/queryHousekeepingFeeConfig',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.housekeepingFeeConfigManageInfo.total = _json.total;
                        $that.housekeepingFeeConfigManageInfo.records = _json.records;
                        $that.housekeepingFeeConfigManageInfo.housekeepingFeeConfigs = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.housekeepingFeeConfigManageInfo.records,
                            dataCount: $that.housekeepingFeeConfigManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listHousekeepingFeeTypes: function (_page, _rows) {
                let param = {
                    params: {
                        page: _page,
                        row: _rows,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/housekeepingFeeType/queryHousekeepingFeeType',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.housekeepingFeeConfigManageInfo.feeTypes = _json.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddHousekeepingFeeConfigModal: function () {
                vc.emit('addHousekeepingFeeConfig', 'openAddHousekeepingFeeConfigModal', {});
            },
            _openEditHousekeepingFeeConfigModel: function (_housekeepingFeeConfig) {
                vc.emit('editHousekeepingFeeConfig', 'openEditHousekeepingFeeConfigModal', _housekeepingFeeConfig);
            },
            _openDeleteHousekeepingFeeConfigModel: function (_housekeepingFeeConfig) {
                vc.emit('deleteHousekeepingFeeConfig', 'openDeleteHousekeepingFeeConfigModal', _housekeepingFeeConfig);
            },
            //查询
            _queryHousekeepingFeeConfigMethod: function () {
                $that._listHousekeepingFeeConfigs(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetHousekeepingFeeConfigMethod: function () {
                $that.housekeepingFeeConfigManageInfo.conditions.feeTypeCd = "";
                $that.housekeepingFeeConfigManageInfo.conditions.feeName = "";
                $that.housekeepingFeeConfigManageInfo.conditions.isDefault = "";
                $that._listHousekeepingFeeConfigs(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _openListHousekeepingFeeConfigModal: function () {
                //跳转到浏览器
                vc.jumpToPage('/#/pages/housekeeping/housekeepingResourceManage');
            },
            _moreCondition: function () {
                if ($that.housekeepingFeeConfigManageInfo.moreCondition) {
                    $that.housekeepingFeeConfigManageInfo.moreCondition = false;
                } else {
                    $that.housekeepingFeeConfigManageInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
